package com.yl.applicationsecurity.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.Assets;
import com.yl.applicationsecurity.pojo.Inspection;
import com.yl.applicationsecurity.pojo.RadarVulnerability;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.AssetsService;
import com.yl.applicationsecurity.service.ScriptStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description: 应用资产控制器
 * @date 2025-02-05 14:42:14
 */
@RestController
@RequestMapping("/assets")
public class AssetsController {

    @Autowired
    private AssetsService assetsService;


    @Autowired
    private ScriptStateService scriptStateService;


    @RequestMapping("/list")
    public Result list(String[] nationSelect, Assets assets, @RequestParam(required = false) Date[] startAndEndFirstDate,  @RequestParam(required = false) Date[] startAndEndLastDate,@RequestParam(defaultValue = "1", value = "pageNum")Integer pageNum
            , @RequestParam(defaultValue = "10", value = "pageSize")Integer pageSize ){
        PageInfo<Assets> assetsList = null;
            assetsList = assetsService.findListByAssets(nationSelect,assets,startAndEndFirstDate,startAndEndLastDate,pageNum,pageSize);
        return Result.success(assetsList);

    }


    @RequestMapping("/updateNation")
    public Result updateNation(String[] id,String updateNation){

        if(assetsService.updateNation(id,updateNation)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }


    @RequestMapping("/update")
    public Result update(String id,Integer type,Integer isWaf,String tag,String nation,String remarks){

        LambdaUpdateWrapper<Assets> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.set(Assets::getNation,nation);
        lambdaUpdateWrapper.set(Assets::getType,type);
        lambdaUpdateWrapper.set(Assets::getIsWaf,isWaf);
        lambdaUpdateWrapper.set(Assets::getTag,tag);
        lambdaUpdateWrapper.set(Assets::getRemarks,remarks);
        lambdaUpdateWrapper.in(Assets::getId , id);

        if(assetsService.update(lambdaUpdateWrapper)){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }


    @RequestMapping("/insert")
    public Result insert(Assets assets) {

        scriptStateService.updateDate("安全雷达-资产");
        if(assetsService.insert( assets)!=0){
            return  Result.success("添加成功");
        }else{
            return  Result.error("添加失败");
        }


    }


}

